package com.jwj.testback.recordsheet.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jwj.testback.recordsheet.pojo.Datasource;
import com.jwj.testback.recordsheet.pojo.TableField;
//import com.jwj.testback.recordsheet.pojo.Tableware;
import com.jwj.testback.recordsheet.pojo.Tableware;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author JWJ
 * @since 2021-12-21
 */
public interface DatasourceMapper extends BaseMapper<Datasource> {

    @Select("SELECT * FROM datasource")
    List<Datasource> showDataBases();

    //清空表数据
    @Select("TRUNCATE TABLE datasource")
    void clearOneTb();

    //根据dsname删除记录
    @Select("DELETE FROM test0.datasource WHERE dsname = #{databaseName}")
    void delDsname(String databaseName);

    //显示所有数据库
    @Select("SHOW DATABASES")
    List<String> showAllBases();

    @Select("SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema=#{databaseName}")
    List<Tableware> showTables(String databaseName);

//    //显示所有表大小
//    @Select("SELECT TABLE_NAME,concat(round((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024,2),'MB') AS DATA FROM information_schema. TABLES WHERE TABLE_SCHEMA = #{databaseName}")
//    List<Tableware> TableSize(String databaseName);

    @Select("select Column_Name,Data_Type,Column_Comment from information_schema.COLUMNS where table_name =#{tableName} and table_schema =#{databaseName}")
    List<TableField> showField(String tableName,String databaseName);

    @Select("SELECT * FROM datasource WHERE dsname=#{databaseName}")
    Datasource showNamePas(String databaseName);


}
